package demo01;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.lang.reflect.Method;

public class Demo {
    public static void main(String[] args) throws Exception{
        //硬编码，效率高，但是写死了
        User user = new User();
        user.sayHello();

        //反射
        Class<?> cls = Class.forName("demo01.User");
        Object obj = cls.newInstance();
        Method method = cls.getMethod("sayHello");
        method.invoke(obj);

        //Spring
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("demo01");
        User user1 = context.getBean(User.class);
        user1.sayHello();


    }
}
